package erfgame.core.graphics.renderer;

import java.util.Map;


import erfgame.core.Rotation;
import erfgame.core.entity.Entity;
import erfgame.core.entity.EntityType;
import erfgame.core.world.World;

public class EntityTypeDelegatingEntityRendererFactoryProxy implements EntityRendererFactory {
	
	private Map<EntityType, EntityRendererFactory> rendererFactories;
	private EntityRendererFactory defaultRendererFactory;
	
	public EntityTypeDelegatingEntityRendererFactoryProxy( Map<EntityType, EntityRendererFactory> rendererFactories, EntityRendererFactory defaultRendererFactory ) {
		this.rendererFactories = rendererFactories;
		this.defaultRendererFactory = defaultRendererFactory;
	}

	public EntityRenderer getRenderer(World world, Entity entity, Rotation viewRotation) {
		EntityRenderer result;
		EntityType entityType = entity.getEntityType();
		EntityRendererFactory rendererFactory = this.rendererFactories.get(entityType);
		if( rendererFactory == null ) {
			rendererFactory = this.defaultRendererFactory;
		}
		if( rendererFactory != null ) {
			result = rendererFactory.getRenderer(world, entity, viewRotation);
		} else {
			result = null;
		}
		return result;
	}

}
